package myfirstproject.firstproject.Mapper;

import myfirstproject.firstproject.domain.DTO.UserGiveUpDTO;
import myfirstproject.firstproject.domain.po.Article;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import myfirstproject.firstproject.domain.po.UserGiveUp;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author author
 * @since 2024-09-24
 */
@Mapper
public interface ArticleMapper extends BaseMapper<Article> {

     @Select("select * from user_give_up where give_up_id = #{id} and is_delete = 0")
     UserGiveUp ContainerId(String id);

     @Insert("insert into user_give_up(article_id, give_up_id) values(#{articleId},#{giveUpId})")
     void addGiveUpInsert(String articleId, String giveUpId);
     @Update("update article set give_up = give_up+1 where id = #{articleId}")
     void addGiveUp(String articleId);

     @Update("update user_give_up set is_delete = 1 where article_id = #{articleId} and give_up_id = #{giveUpId}")
     void cancelGiveUp(UserGiveUpDTO userGiveUpDTO);

     @Update("update article set give_up = give_up-1 where id = #{articleId}")
     void deleteGiveUp(UserGiveUpDTO userGiveUpDTO);
}
